package com.studerb.model;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.studerb.dao.TimeStampedEntity;

public class Server extends TimeStampedEntity {

    private String host;
    private Integer port = org.apache.commons.net.nntp.NNTP.DEFAULT_PORT;
    private Integer connections;
    private String userName;
    private String password;
    private Boolean master = false;
    private Boolean authRequired;
    private Boolean connectedAlready = false;
    private Integer errorsAlready = 0;

    public Server() {
    }

    public Server(String host, Integer port, Integer connections, String userName, String password, Boolean master, Boolean authRequired) {
        this.host = host;
        this.port = port;
        this.connections = connections;
        this.userName = userName;
        this.password = password;
        this.master = master;
        this.authRequired = authRequired;
    }

    @Override public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        if(obj == null){
            return false;
        }
        if(getClass() != obj.getClass()){
            return false;
        }
        final Server other = (Server)obj;
        if(authRequired == null){
            if(other.authRequired != null){
                return false;
            }
        }
        else if( !authRequired.equals(other.authRequired)){
            return false;
        }
        if(host == null){
            if(other.host != null){
                return false;
            }
        }
        else if( !host.equals(other.host)){
            return false;
        }
        if(password == null){
            if(other.password != null){
                return false;
            }
        }
        else if( !password.equals(other.password)){
            return false;
        }
        if(port == null){
            if(other.port != null){
                return false;
            }
        }
        else if( !port.equals(other.port)){
            return false;
        }
        if(userName == null){
            if(other.userName != null){
                return false;
            }
        }
        else if( !userName.equals(other.userName)){
            return false;
        }
        return true;
    }

    public Integer getConnections() {
        return connections;
    }

    public Integer getErrorsAlready() {
        return errorsAlready;
    }

    public String getHost() {
        return host;
    }

    public String getPassword() {
        return password;
    }

    public Integer getPort() {
        return port;
    }

    public String getUserName() {
        return userName;
    }

    @Override public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (authRequired == null ? 0 : authRequired.hashCode());
        result = prime * result + (host == null ? 0 : host.hashCode());
        result = prime * result + (password == null ? 0 : password.hashCode());
        result = prime * result + (port == null ? 0 : port.hashCode());
        result = prime * result + (userName == null ? 0 : userName.hashCode());
        return result;
    }

    public Boolean isAuthRequired() {
        return authRequired;
    }

    public Boolean isConnectedAlready() {
        return connectedAlready;
    }

    public Boolean isMaster() {
        return master;
    }

    public void setAuthRequired(Boolean authRequired) {
        this.authRequired = authRequired;
    }

    public void setConnectedAlready(Boolean connectedAlready) {
        this.connectedAlready = connectedAlready;
    }

    public void setConnections(Integer connections) {
        this.connections = connections;
    }

    public void setErrorsAlready(Integer errorsAlready) {
        this.errorsAlready = errorsAlready;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public void setMaster(Boolean isMaster) {
        master = isMaster;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public void setUserName(String user) {
        userName = user;
    }

    @Override public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}